﻿using Learun.Application.TwoDevelopment.ZZDT_EC;
using Learun.Util;
using System;
using System.Collections.Generic;
using System.Web.Http;

namespace Learun.Application.Web.AppApi
{
    /// <summary>
    /// 虚拟点（By YuXH）。
    /// 23 11 24，进行改造。由于客户希望虚拟点也会关联通道，所以干脆也用<see cref="ec_Wire_GroupEntity"/>这个类去对待
    /// 这个接口准备弃用
    /// </summary>
    [HandlerApiLogin(FilterMode.Enforce)]
    [TokenAuthorize]
    [Obsolete("由于客户希望虚拟点也会关联通道，所以干脆也用ec_Wire_GroupEntity这个类去对待")]
    public class SofttagApiController : WebApiControllerBase
    {
        #region 模块对象
        private ec_SofttagBLL softTagBLL = new ec_SofttagBLL();
        #endregion

        #region 信號相關
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="projId"></param>
        /// <param name="wireGroupId">如果为0，则查询所有。否则，就是查某一个信号下的虚拟点集合</param>
        /// <returns></returns>
        [HttpGet]
        [Obsolete]
        public IHttpActionResult GetSoftTags(string projId, string wireGroupId = "0")
        {
            var res = softTagBLL.GetList(projId, wireGroupId);
            return Success(res);
        }
        /// <summary>
        /// 批量保存（增、改）虚拟点。传入集合
        /// </summary> 
        /// <param name="projId"></param>
        /// <returns></returns>
        [HttpPost]
        [Obsolete]
        public IHttpActionResult SaveSoftTags(string projId)
        {

            try
            {
                var asyncContent = Request.Content.ReadAsStringAsync().Result;
                var entity = asyncContent.ToObject<List<ec_SofttagEntity>>();
                foreach (var item in entity)
                {
                    var id = item.CS_TAG_ID;
                    softTagBLL.SaveEntity(projId,ref id , item);
                    item.CS_TAG_ID = id;
                }

                return Success(entity);
            }
            catch (Exception e)
            {

                return Fail(e.Message);
            }
        }
        /// <summary>
        /// 删除虚拟点
        /// </summary> 
        /// <param name="projId"></param>
        /// <param name="csTagId">删除多个，以逗号隔开</param>
        /// <returns></returns>
        [HttpPost]
        [Obsolete]
        public IHttpActionResult Delete(string projId, string csTagId)
        {

            try
            {
                var IDs = csTagId.Split(',');
                foreach (var Id in IDs)
                {
                    softTagBLL.DeleteEntity(projId, Id);
                }

                return Success("OK");
            }
            catch (Exception e)
            {

                return Fail(e.Message);
            }
        }
        #endregion
    }
}